package wang.Seacher.seven.pipeline;

import java.time.LocalDateTime;
import java.util.List;

import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;

import wang.Seacher.seven.bean.PictureVo;
import wang.Seacher.seven.bean.picBox;
import wang.Seacher.seven.engine.DownPic;
import wang.Seacher.util.DateTimeStyle;
import wang.Seacher.util.JudgeUtil;

@PipelineName("getPicBoxPipeline")
public class GetPicBoxPipeline implements Pipeline<picBox> {

	@Override
	public void process(picBox bean) {
		LocalDateTime startTime = LocalDateTime.now();
		
		HttpRequest request = bean.getRequest();
		
		if (JudgeUtil.isPresent(bean)) {
			PictureVo pictureVo = bean.getPictureVo();
			if (JudgeUtil.isPresent(pictureVo)) {
				DownPic.downPic(pictureVo, bean.getRequest());
				getNextPage(request, pictureVo.getHerf());

			}
		} else {
			System.out.println("没图片了");
		}
		
		System.out.println(DateTimeStyle.duration(startTime)+"\n");
	}
	
	private void getNextPage(HttpRequest currRequest, String nextUrl) {
		// 下一页继续抓取
		System.out.println("nextUrl====>" + nextUrl);
		SchedulerContext.into(currRequest.subRequest(nextUrl));
	}

}
